package com.aegis.manage.api;

import com.aegis.manage.api.dto.SysUserDTO;
import com.aegis.manage.api.request.CreateUserRequest;
import com.aegis.manage.api.service.UserServiceApi;
import com.aegis.manage.api.vo.UserDetailVO;
import com.aegis.manage.model.dos.SysUser;
import com.aegis.manage.service.sys.user.SysUserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author renogo
 * 
 * @Version 1.0
 */
@Service
@DubboService
public class UserServiceApiImpl implements UserServiceApi {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public SysUserDTO getUserByUsernameAndPwd(String username, String rsaEncodePwd) {
        SysUser sysUser = sysUserService.getUserByUsernameAndPwd(username, rsaEncodePwd);
        if (sysUser == null) {
            return null;
        }
        SysUserDTO sysUserDTO = new SysUserDTO();
        return (SysUserDTO) sysUserDTO.convert(sysUser);
    }

    @Override
    public SysUserDTO getUserDetailById(String userId) {
        UserDetailVO userDetailById = sysUserService.getUserDetailById(userId);
        if (userDetailById == null) {
            return null;
        }
        SysUserDTO sysUserDTO = new SysUserDTO();
        return (SysUserDTO) sysUserDTO.convert(userDetailById);
    }

    @Override
    public String createUser(CreateUserRequest req) {
        return sysUserService.createUser(req);
    }
}
